package someTestExcemple.huaweiOd.container.array;
import java.util.*;
//华为OD机试 - 围棋的气 - 数组（Java 2024 D卷 100分）
//https://blog.csdn.net/guorui_java/article/details/138310165
public class ChessAirCount {
    //棋盘
    private static int[][] chessBoard = new int[19][19];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        String[] s2 = sc.nextLine().split(" ");
        sc.close();

        //解析坐标并下棋
        int[][] blackChess = parseChessPosition(s1,chessBoard,1); //1表示黑棋
        int[][] whiteChess = parseChessPosition(s2,chessBoard,2); //2.表示白棋
        System.out.println(Arrays.deepToString(chessBoard));
        //计算各自的气 --遍历上下左右看是不是空的格子，即=0
        //为避免重复计算，用HashMap存计算的气位置，应为key不能重复，如果以存在，不会重复计算
        System.out.println(countAir(blackChess,chessBoard)+" "+countAir(whiteChess,chessBoard));

    }
    public static int[][] parseChessPosition(String[] chess, int[][] chessBoard,int color) {
            //棋子坐标
            int[][] chessPosition = new int[chess.length/2][2];
            for (int i = 0; i < chess.length; i+=2) {
                int x = Integer.parseInt(chess[i]);
                int y = Integer.parseInt(chess[i+1]);
                chessPosition[i/2][0] = x;
                chessPosition[i/2][1] = y;
                chessBoard[x][y] = color;
            }
            return chessPosition;
    }
    public static int countAir(int[][] chessPosition,int[][] chessBoard) {
        //有气的位置
        HashMap<String,Integer> aipPosition = new HashMap<>();
        //上下左右搜索遍历
        int[] dx = {0,0,1,-1};
        int[] dy ={-1,1,0,0};
        for(int i = 0; i < chessPosition.length; i++) {
            int x = chessPosition[i][0];
            int y = chessPosition[i][1];
            for(int j = 0; j < 4; j++) {
                int  airX = x+dx[j];
                int  airY = y+dy[j];
                if(airX >=0 && airX <19 && airY >=0 && airY <19) {
                    //该位置是空的 有气
                    if(chessBoard[airX][airY] == 0) {
                        //hashMap的key不能重复，如果重复，会覆盖 所以只会计算一次
                        aipPosition.put(airX+","+airY,3);
                    }
                }
            }
        }
        System.out.println(aipPosition);
        return aipPosition.size();
    }
}
/**
 * 0 5 8 9 9 10
 * 5 0 9 9 9 8
 */